package com.lingyue.commons.enums;

import com.lingyue.commons.constants.CampaignTypeOption;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 *
 * @Description: TODO
 * @Author: BaiJinhua
 * @Date: 2019/12/18 14:25
 * @See: com.lingyue.commons.enums
 * @Version: 1.0
 * Copyright: Copyright (c) 2019
 */
public enum CampaignTypeEnum implements CommEnum<String> {

    FINANCIAL(CampaignTypeOption.OPTION_SF, "金融"),
    AFTER_SALE(CampaignTypeOption.OPTION_AFS, "售后"),
    USED_CAR(CampaignTypeOption.OPTION_UC, "二手车"),
    CRM(CampaignTypeOption.OPTION_CRM, "CRM"),
    ALL(CampaignTypeOption.OPTION_DEFAULT, "ALL");

    private String code;
    private String content;

    CampaignTypeEnum(String code, String content) {
        this.code = code;
        this.content = content;
    }

    @Override
    public String getCode() {
        return this.code;
    }

    @Override
    public String getContent() {
        return this.content;
    }

    public static CampaignTypeEnum getTypeByCode(String code) {
        for (CampaignTypeEnum item : values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }

    public static String getMsg(String code) {
        for (CampaignTypeEnum item : values()) {
            if (item.getCode().equals(code)) {
                return item.getContent();
            }
        }
        return "";
    }

    /**
     * 售后类型状态和
     *
     * @return
     */
    public static String[] getAfterSaleStatus(List<String> roles) {
        Set<String> set = new HashSet<>();
        String[] array = {
                CampaignEnum.UNTREATED.value(),
                CampaignEnum.FOLLOW.value(),
                CampaignEnum.CUSTOMER_RESERVATION.value(),
                CampaignEnum.EXPERT_ADVICE.value(),
                CampaignEnum.CUSTOMER_TO_SHOP.value(),
                CampaignEnum.CUSTOMER_REJECTION.value(),
                CampaignEnum.NSP_REJECTION.value()
        };
        set.addAll(new HashSet(Arrays.asList(array)));
        if (!roles.contains(LevelEnum.COMMISSIONER.getContent())) {
            set.add(CampaignEnum.UNALLOCATED.value());
        }
        return set.toArray(new String[set.size()]);
    }

    /**
     * 金融类型状态和
     *
     * @return
     */
    public static String[] getFinancialStatus(List<String> roles) {
        Set<String> set = new HashSet<>();
        String[] array = {
                CampaignEnum.UNTREATED.value(),
                CampaignEnum.FOLLOW.value(),
                CampaignEnum.CUSTOMER_RESERVATION.value(),
                CampaignEnum.EXPERT_ADVICE.value(),
                CampaignEnum.WILLING_CUSTOMER.value(),
                CampaignEnum.CUSTOMER_TO_SHOP.value(),
                CampaignEnum.SF_TRANSACTION.value(),
                CampaignEnum.CUSTOMER_REJECTION.value(),
                CampaignEnum.NSP_REJECTION.value()
        };
        set.addAll(new HashSet(Arrays.asList(array)));
        if (!roles.contains(LevelEnum.COMMISSIONER.getContent())) {
            set.add(CampaignEnum.UNALLOCATED.value());
        }
        return set.toArray(new String[set.size()]);
    }

    /**
     * 二手车类型状态和
     *
     * @return
     */
    public static String[] getUsedCarStatus(List<String> roles) {
        Set<String> set = new HashSet<>();
        String[] array = {
                CampaignEnum.UNTREATED.value(),
                CampaignEnum.FOLLOW.value(),
                CampaignEnum.CUSTOMER_RESERVATION.value(),
                CampaignEnum.EXPERT_ADVICE.value(),
                CampaignEnum.SUCCESS_VISIT.value(),
                CampaignEnum.CUSTOMER_TO_SHOP.value(),
                CampaignEnum.UC_TRANSACTION.value(),
                CampaignEnum.CUSTOMER_REJECTION.value(),
                CampaignEnum.NSP_REJECTION.value()
        };
        set.addAll(new HashSet(Arrays.asList(array)));
        if (!roles.contains(LevelEnum.COMMISSIONER.getContent())) {
            set.add(CampaignEnum.UNALLOCATED.value());
        }
        return set.toArray(new String[set.size()]);
    }

    /**
     * 二手车类型状态和
     *
     * @return
     */
    public static String[] getCrmStatus(List<String> roles) {
        Set<String> set = new HashSet<>();
        String[] array = {
                CampaignEnum.UNTREATED.value(),
                CampaignEnum.FOLLOW.value(),
                CampaignEnum.EXPERT_ADVICE.value(),
                CampaignEnum.SUCCESS_VISIT.value(),
                CampaignEnum.CUSTOMER_REJECTION.value(),
                CampaignEnum.NSP_REJECTION.value()
        };
        set.addAll(new HashSet(Arrays.asList(array)));
        if (!roles.contains(LevelEnum.COMMISSIONER.getContent())) {
            set.add(CampaignEnum.UNALLOCATED.value());
        }
        return set.toArray(new String[set.size()]);
    }

    /**
     * 获取对应类型所有状态
     *
     * @param roles
     * @param type
     * @return
     */
    public static String[] getAllStatus(List<String> roles, String type) {
        switch (getTypeByCode(type)) {
            case FINANCIAL:
                return getFinancialStatus(roles);
            case AFTER_SALE:
                return getAfterSaleStatus(roles);
            case USED_CAR:
                return getUsedCarStatus(roles);
            case CRM:
                return getCrmStatus(roles);
            default:
                return getAllStatus(roles);
        }
    }

    public static String[] getAllStatus(List<String> roles) {
        Set<String> set = new HashSet<>();
        String[] all = {
                CampaignEnum.UNTREATED.value(),
                CampaignEnum.FOLLOW.value(),
                CampaignEnum.CUSTOMER_RESERVATION.value(),
                CampaignEnum.EXPERT_ADVICE.value(),
                CampaignEnum.CUSTOMER_REJECTION.value(),
                CampaignEnum.NSP_REJECTION.value(),
                CampaignEnum.CUSTOMER_TO_SHOP.value(),
                CampaignEnum.WILLING_CUSTOMER.value(),
                CampaignEnum.SF_TRANSACTION.value(),
                CampaignEnum.UC_TRANSACTION.value(),
                CampaignEnum.SUCCESS_VISIT.value()
        };
        set.addAll(new HashSet(Arrays.asList(all)));
        if (!roles.contains(LevelEnum.COMMISSIONER.getContent())) {
            set.add(CampaignEnum.UNALLOCATED.value());
        }
        return set.toArray(new String[set.size()]);
    }

}
